package top.wettis.chat.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.wettis.chat.constant.ResultCode;
import top.wettis.chat.constant.ResultType;
import top.wettis.chat.pojo.DO.Expert;
import top.wettis.chat.pojo.DO.JobImfor;
import top.wettis.chat.pojo.VO.Result;
import top.wettis.chat.service.impl.JobImforServiceImpl;

import java.util.List;

/**
 * <p>
 * 具体职业信息 前端控制器
 * </p>
 *
 * @author wettis
 * @since 2023-04-13
 */
@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/chat/jobImfor")
public class JobImforController {
    @Autowired
    private JobImforServiceImpl jobImforService;


    /**
     * 查询列表
     */
    @GetMapping("/list")
    @ResponseBody
    private Result<Object> selectall(@RequestParam("JobName") String JobName) {
        List<JobImfor> list = jobImforService.expertPage(JobName);
        if (list == null) {
            return Result.failInfo(ResultType.GET, null);
        }
        return Result.successInfo(ResultType.GET, list);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public Result<Object> Save(@RequestBody JobImfor jobImfor) {

        jobImforService.save(jobImfor);
        return Result.successInfo(ResultType.SAVE, "添加成功");
    }

    /**
     * 删除
     */

    @DeleteMapping("/delete/{id}")
    public Result<Object> Delete(@PathVariable Integer id) {
        jobImforService.removeById(id);
        return Result.successInfo(ResultType.DELETE, ResultCode.DELETE_OK);
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result<Object> Update(@RequestBody JobImfor jobImfor) {
        jobImforService.updateById(jobImfor);
        return Result.successInfo(ResultType.UPDATE, ResultCode.UPDATE_OK);
    }


    /**
     * 查询id
     */
    @GetMapping("/select/{id}")
    public Result<Object> select(@PathVariable Integer id) {
        JobImfor jobImfor = jobImforService.getById(id);
        if (jobImfor != null) {
            return Result.successInfo(ResultType.GET, ResultCode.GET_OK);
        } else {
            return Result.successInfo(ResultType.GET, ResultCode.GET_ERR);
        }

    }


}
